package com.theo.service.impl;

import com.theo.entity.MaskInfo;
import com.theo.entity.OrderInfo;
import com.theo.entity.VaccineInfo;
import com.theo.mapper.MaskInfoMapper;
import com.theo.mapper.OrderInfoMapper;
import com.theo.mapper.VaccineInfoMapper;
import com.theo.service.MaskInfoService;
import com.theo.service.OrderInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.theo.service.VaccineInfoService;
import io.swagger.models.auth.In;
import org.mapstruct.ValueMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 方涛
 * @since 2021-03-31
 */
@Service
public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo> implements OrderInfoService {

    @Autowired
    private OrderInfoMapper orderInfoMapper;
    @Autowired
    private MaskInfoMapper maskInfoMapper;
    @Autowired
    private MaskInfoService maskInfoService;
    @Autowired
    private VaccineInfoMapper vaccineInfoMapper;
    @Autowired
    private VaccineInfoService vaccineInfoService;

    @Override
    public int saveMaskOrderInfo(OrderInfo orderInfo) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        orderInfo.setOrderCode(sdf.format(new Date()));
        MaskInfo maskInfo = maskInfoService.queryMaskInfoById(orderInfo.getArticleId());
        float price = maskInfo.getMaskPrice() * orderInfo.getOrderNum();
        orderInfo.setOrderPrice(price);
        return orderInfoMapper.insert(orderInfo);
    }

    @Override
    public int deleteOrderInfo(Integer id) {
        return orderInfoMapper.deleteById(id);
    }

    @Override
    public int updateOrderInfo(OrderInfo orderInfo) {
        return orderInfoMapper.updateById(orderInfo);
    }

    @Override
    public List<OrderInfo> queryAllOrderInfo() {
        return orderInfoMapper.queryAllOrderInfo();
    }

    @Override
    public OrderInfo queryOrderInfoById(Integer id) {
        return orderInfoMapper.selectById(id);
    }
}
